//
//  PhoneViewController.swift
//  IDF
//
//  Created by 陈徐挺 on 23/03/2018.
//  Copyright © 2018 Jesse.chen. All rights reserved.
//

import UIKit
import SVProgressHUD

enum LoginType {
    case register
    case findpassword
}

class PhoneViewController: BaseViewController {
    var type: LoginType = .register
    
    @IBOutlet weak var phoneTF: UITextField!
    @IBOutlet weak var nextBtn: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        var title = "Sign Up"
        if type == .findpassword {
            title = "Retrieve the password"
        }
        navigationItem.title = title
        
        phoneTF.addTarget(self, action: #selector(textTextFieldContextChange(_:)), for: .editingChanged)
        nextBtn.alpha = 0.4
        nextBtn.isEnabled = false
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func nextClick(_ sender: UIButton) {
        appUser.phone = phoneTF.text
        let next = initViewContollerWithStoryboard(storyboardName: "Home", storyboardId: "sMSCodeViewController")
        SVProgressHUD.show()
        appUser.getVerificateCode().then{ _ -> Void in
            nowNavgationController.pushViewController(next, animated: true)
        }
        
    }
    
    
    @objc func textTextFieldContextChange(_ sender: UITextField) {
        let text = sender.text!
        if text.characters.count != 0 {
            nextBtn.isEnabled = true
            nextBtn.alpha = 1
        } else {
            nextBtn.isEnabled = false
            nextBtn.alpha = 0.4
        }
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
